package com.szxy.plugin;

import com.deepoove.poi.data.RowRenderData;
import com.deepoove.poi.policy.DynamicTableRenderPolicy;
import com.deepoove.poi.policy.MiniTableRenderPolicy;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;

import java.util.List;

/**
 * @Author: zwz
 * @Date:2020/7/29 11:34
 * @Description:com.szxy.plugin
 * @Version:1.0
 **/
public class SelfPowerMarketTablePolicy extends DynamicTableRenderPolicy {

    /**
     * 起始行
     */
    public static int START_ROWS = 2;

    @Override
    public void render(XWPFTable table, Object data) {
        // 数据校验
        if (null == data) return;
        // 数据准备
        List<RowRenderData> dataList = (List<RowRenderData>) data;
        // 删除当前行
        table.removeRow(START_ROWS);
        if (null != dataList) {
            for (int i = 0; i < dataList.size(); i++) {
                // 新增行
                XWPFTableRow insertNewTableRow = table.insertNewTableRow(i+START_ROWS);
                // 新增单元格
                for (int j = 0; j < 8; j++)  insertNewTableRow.createCell();
                // 渲染行数据
                MiniTableRenderPolicy.renderRow(table, i+START_ROWS, dataList.get(i));
            }
        }
    }
}
